CREATE FUNCTION GetTagSubTree
(
	@tagID int
)
RETURNS TABLE 
AS
RETURN
(
	WITH TagTree(ID) AS
	(
		(SELECT @tagID AS ID)
		UNION ALL
		(SELECT tg.ID FROM Tag AS tg JOIN TagTree AS recCTE ON tg.ParentID = recCTE.ID)
	)

	SELECT ID FROM TagTree
)
GO
